const app = new Vue({
  el: '#app',
  data: {
    books: [
      {
        id: 1,
        name: "《aasd》",
        data: "2006-9",
        price: 51.00,
        count: 1
      },
      {
        id: 2,
        name: "《a3d》",
        data: "2016-9",
        price: 70.00,
        count: 1
      },
      {
        id: 3,
        name: "《aa125d》",
        data: "2009-7",
        price: 81.00,
        count: 1
      },
      {
        id: 4,
        name: "《123sd》",
        data: "2019-9",
        price: 20.00,
        count: 1
      },
      {
        id: 5,
        name: "《a888asd》",
        data: "2000-9",
        price: 101.00,
        count: 1
      }
    ]
  },
  methods: {
    decrement(index) {
      this.books[index].count--;
    },
    increment(index) {
      this.books[index].count++;
    },
    removeHandle(index) {
      this.books.splice(index, 1)
    }
  },
  computed: {
    TotalPrice() {
      let totalPrice = 0;
      for (let i = 0; i < this.books.length; i++) {
        totalPrice += this.books[i].price * this.books[i].count
      }
      return totalPrice;
    }
  },
  filters: {
    showPrice(price) {
      return "￥" + price.toFixed(2);
    }
  }
})